<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<%@ page import="com.hzqy.commons.utils.ConstantUtils" %>
<%@ taglib prefix="limits" uri="/WEB-INF/tld/limits.tld"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>剧集</title>
<%
	int f_ssc_contentid = 0;
	String para = request.getParameter("f_cc_id");
	if(para!=null)
		f_ssc_contentid = Integer.valueOf(para);
	String []nonceObj=ConstantUtils.getNonceObject();
%>
<link rel="stylesheet" type="text/css"	href="../static/js/themes/defalut.css">
<link rel="stylesheet" type="text/css"	href="../static/js/themes/public.css">
<link rel="stylesheet" type="text/css"	href="../static/js/themes/ddspstyle.css">
<link rel="stylesheet" type="text/css"	href="../static/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"	href="../static/js/themes/icon.css">
<!-- <link href="../static/css/uploadify.css" rel="stylesheet" type="text/css"/> -->

<script type="text/javascript" src="../static/js/jquery.min.js"></script>
<script type="text/javascript" src="../static/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../static/js/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="../static/js/index.js"></script>
<!-- <script src="../static/js/jquery.uploadify.js" type="text/javascript"></script> -->
<script src="../static/js/jquery.uploadifive.js" type="text/javascript"></script>
<link href="../static/css/uploadifive.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript">
		var queryParams;
		function EasyuiDatagrid() {
			$("#easyui-datagrid").datagrid({
				url: 'series_list.do',
				nowrap: true,
				striped: true,
				border: false,
				fit: true,
				rownumbers:true,
				queryParams: getGueryParams(),
				columns: [[
					{field:'id',checkbox:true},
					{field:'f_ssc_id',title:'剧集ID',align:'center',width:100},
					{field:'f_ssc_name',title:'剧集名称',align:'center',width:100},
					{field:'f_ssc_viewindex',title:'剧集排序',align:'center',width:100},
					{field:'f_ssc_isfree',title:'收费状况',align:'center',width:60,
						formatter:function(value,row,index) {
							var status = "收费";
							if(value==0){
								status="收费";
							} else if(value==1){
								status="免费";
							}
							return status;
						}	
					},
					{field:'f_ssc_status',title:'状态',align:'center',width:100,
						formatter:function(value,row,index) {
							var status = "未知";
							if(value==1){
								status="有效";
							} else if(value==2){
								status="无效";
							} else if(value==4){
								status="有效但不可播";
							}
							return status;
						}	
					},
					{field:'f_ssc_cdate',title:'创建时间',align:'center',width:150},
					{field:'f_ssc_udate',title:'修改时间',align:'center',width:150},
					{field:'_type',title:'操作',align:'center',width:250,
						formatter:function(value,row,index){
							str ="";
							str= '<a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="onClickBtnDelete(\''+row.f_ssc_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-remove l-btn-icon-left">删除</span></span></a>';
							str+= '<a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="edit(\''+row.f_ssc_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-edit l-btn-icon-left">修改</span></span></a>';
				    		str+= '<a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="show(\''+row.f_ssc_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-search l-btn-icon-left">详情</span></span></a>';
					    	return str;
				    	}
					}
				]],
				singleSelect:false,
				pagination:true,
				pageList:[10,20,30,40,50],
				pageSize:10,
				toolbar: '#toolbar',
				
				onExpandRow: function(index,row){
				
				},
				onSelect: function(rowIndex,rowData) {
					
				},
				onUnselect: function(rowIndex,rowData) {
					
				},
				onCheckAll: function(rowIndex,rowData) {
					
				},
				onUncheckAll: function(rowIndex,rowData) {
				
				},
				onLoadSuccess: function(data) {
					if(data.total==-1) {
						$.messager.defaults={ok:"确定",cancel:"取消"};
						$.messager.confirm('提示', '用户尚未登录,请登录', function(r){
						if (r){
						    window.parent.location.href='/login.do';
						    return false;
						}});
					}
				}
			});
		}
	
		function getGueryParams(){
			return {
				f_ssc_name:$("#f_ssc_name").val(),
				f_ssc_status:$("#f_ssc_status").val(),
				f_ssc_contentid:$("#f_ssc_contentid").val()
			};
		}
		
		$(function(){
			$("#f_ssc_contentid").val(<%=f_ssc_contentid%>);
			new EasyuiDatagrid();
			gotoSearch = function(){
				$("#easyui-datagrid").datagrid('reload',getGueryParams());
			};
			
			onClickBtnDelete = function(id){
				$.messager.confirm('确定删除内容','确定删除内容么?',function(r){
					if(r){
						app_ajax('delete_series.do?f_ssc_status=3&f_ssc_ids='+id+"&stime=<%=nonceObj[0]%>&sign=<%=nonceObj[1]%>",
						'',
						function(msg){
							if(msg.success) {
								alert("删除成功!");
								if (checkAjaxRequestValidity(msg)) {
									gotoSearch($('#easyui-treegrid'));
								}
							} else {
								alert("删除异常，请联系管理员");
								if($.isFunction(window.showMessager)){
									window.showMessager(msg.resultTitle,msg.result);
								}
							}
							window.location.reload();
						}
						);
					}
				});
			};
		});
		
		function SubgridTabOnSelect(title,index){
			setTimeout(function(){
				$("#easyui-datagrid").datagrid('fixDetailRowHeight',index);
			},300);
			setTimeout(function(){
				$("#easyui-datagrid").datagrid('fixDetailRowHeight',index);
			},3000);
	    }
		
		function load(){
			$(".datagrid-row-expander datagrid-row-expand").attr("display","none"); 
		}
		
		function _resert(){
			$("#f_cc_name").val("");
			$("#f_cc_status").val("");
		}
		
		function onpress(){
			var event=arguments.callee.caller.arguments[0]||window.event;//消除浏览器差异
	   		  	if (event.keyCode == 13){  
	      			gotoSearch($('#easyui-treegrid'));
	    		}
		}
		
		function edit(id){
			openDialog($("#dlg"),'series_update.jsp?f_ssc_id='+id);
		}
		
		function show(id){
			openDialog($('#dlg'),'series_info.jsp?f_ssc_id='+id);
		}
		
		function add(){
			var f_ssc_contentid = $("#f_ssc_contentid").val();
			openDialog($('#dlg'),'series_add.jsp?f_ssc_contentid='+f_ssc_contentid);
		}
		
		function ButonGetCheck(f_ssc_status){
			var checkedItems = $('#easyui-datagrid').datagrid('getChecked');
			var names = [];
			$.each(checkedItems, function(index, item){
				names.push(item.f_ssc_id);
			}); 
			if(names.length<=0) {
				alert("请选择需要批量处理的记录!");
				return;
			}
			var f_ssc_ids = names.join(",");
			app_ajax('delete_series.do?f_ssc_status='+f_ssc_status+'&f_ssc_ids='+f_ssc_ids+"&stime=<%=nonceObj[0]%>&sign=<%=nonceObj[1]%>",
				'',
				function(msg){
					if(msg.success) {
						alert("批量处理成功!");
						if (checkAjaxRequestValidity(msg)) {
							gotoSearch($('#easyui-treegrid'));
						}
					} else {
						alert("批量处理异常，请联系管理员");
						if($.isFunction(window.showMessager)){
							window.showMessager(msg.resultTitle,msg.result);
						}
					}
					window.location.reload();
				}
			);
		}
		
	</script>
</head>
<body onload="load();">
	<input type="hidden" id="sessionId" value="${pageContext.session.id}" />
	<input type="hidden" id="f_ssc_contentid" name="f_ssc_contentid" value="" />
	<table id="easyui-datagrid" title="剧集列表"></table>
	<div id="toolbar" class="easyui_datagrid_toolbar" style="">
		<div class="easyuiSearch">
			<form onsubmit="return false;" method="post">
				<table cellspacing="0" cellpadding="0" width="90%">
					<tr>
						<td align="right" width="10%">剧集名称：</td>
						<td align="left" width="20%"><input name="f_ssc_name"
							id="f_ssc_name" style="width: 150px;" onkeydown="onpress();" /></td>
						<td align="right" width="10%">剧集状态：</td>
						<td align="left" width="10%"><select id="f_ssc_status"
							name="f_ssc_status">
								<option value="0">请选择</option>
								<option value="1">有效</option>
								<option value="2">无效</option>
						</select></td>
						<td align="left" width="10%"><limits:uiAuth
								url="content_list.do">
								<a href="javascript:void(0);" class="easyui-linkbutton"
									data-options="iconCls:'icon-search', plain:true"
									onclick="gotoSearch($('#easyui-datagrid'))">查询</a>
							</limits:uiAuth></td>
						<td align="left" width="15%">
								<a href="javascript:void(0);" class="easyui-linkbutton"
									data-options="iconCls:'icon-add', plain:true" onclick="add()">增加内容</a>
								<a href="javascript:void(0);" class="easyui-linkbutton"
								data-options="iconCls:'icon-add', plain:true" onclick="batch_add()">批量上传</a>
						</td>
						<td>
							<a href="javascript:void(0);" class="easyui-linkbutton"
								data-options="iconCls:'icon-remove', plain:true" onclick="ButonGetCheck(2)">批量失效</a>
							<a href="javascript:void(0);" class="easyui-linkbutton"
								data-options="iconCls:'icon-edit', plain:true" onclick="ButonGetCheck(1)">批量生效</a>
						</td>
					</tr>
				</table>
			</form>
		</div>
		<div style="margin-bottom: 5px">
			<!-- <a href="javascript:void(0)" class="easyui-linkbutton" onclick="delete();" iconCls="icon-cut" plain="true">删除</a>  -->
		</div>
	</div>
	<div id="dlg" class="easyui-dialog"
		style="width: 600px; height: 480px; padding-top: 0px;"
		data-options="title:'剧集管理', iconCls:'icon-save',modal:true,closed:true,buttons:'#dlg_buttons'">
		<iframe scrolling="auto" frameborder="0"
			style="width: 100%; height: 99%;"></iframe>
	</div>
	
	<div id="win" class="easyui-window" closed="true" modal="true" iconCls="icon-save" style="width:400px; height: 250px; left: 50%px;top: 30%;" title="剧集批量导入">
		<div class="easyui-layout" fit="true">
			<div region="north" border="true" style="height: 40;">
				<a class="easyui-linkbutton" style="line-height: 20px; padding-bottom: 3px;" iconCls="icon-undo" plain="true" href="../static/excel/剧集批量导入模版.xlsx">下载模版&nbsp;</a>
			</div>
			
			<div region="center" border="true">
				<div>
					<p>
						<font size="6" style="font-weight: bold;color: gray;">批量导入说明:</font><br/>
						&nbsp;&nbsp;1. 类型 :剧集<br/>
						&nbsp;&nbsp;2. 所有剧集都收费<br/>
					</p>
				</div>
			</div>
			
			<div region="south" border="false" style="text-align:left;height:40px;padding: 3px">
				<input id="uploadFile2"  type="file" name="file"/>
			</div>
			
		</div>
	</div>
</body>
<script type="text/javascript">
	$(function(){
		$('#win').window({
	       onBeforeClose:function(){ 
				//window.location.reload();	
	       }
		});
		initFileUpload2("#uploadFile2", {});
	});
	
	function batch_add(){
		$('#win').window('open');
	}
	
	function initFileUpload(inputId, params){
		var action = 'insert_batch_series.do;jsessionid='+$("#sessionId").val();
		$(inputId).uploadify({
			'swf'           :'../swf/uploadify.swf',
			'uploader'      :action,
			'formData'      :params,
			'fileObjName'   :'uploadify',
			'queueId'		:"fileQueue",
			'fileTypeDesc'  :"Excel File",
			'fileTypeExts'	:"*.xls; *.xlsx",//限制文件类型
			'auto'			:true,//是否自动上传
			'multi'			:false,//是否允许多文件上传
			'buttonText'	:"导入文档",
			'method'		:"POST",
			'onInit'        : function(){
			},
			'onUploadStart' : function(file){
					jQuery.messager.alert('批量导入','批量导入开始, 操作结果请稍后.');
					$(inputId).uploadify('settings','formData', {"f_ssc_contentid" : <%=f_ssc_contentid%>});
			},
			'onUploadSuccess' : function(file,data,response) {
				if(data != null && data != undefined && data != ''){
					jQuery.messager.alert('批量导入',data);
				}
			},
			'onUploadError' : function(file, errorCode, errorMsg, errorString) {
				if(errorMsg == '302'){
					jQuery.messager.alert('批量导入','批量导入失败，请检查登录状态或者无此权限!');
				}
	        }
		});
	}
	function initFileUpload2(inputId, params){
		var action = 'insert_batch_series.do;jsessionid='+$("#sessionId").val();
		$(inputId).uploadifive({
			'swf'           :'../swf/uploadify.swf',
            'uploadScript'  :action,
            'fileObjName'   :'uploadify',
            'cancelImg' 	:"../imgs/uploadify-cancel.png",
            'queueId'		:"fileQueue",
            'fileTypeDesc'  :"Excel File",
            'fileType'	    :"*.xls; *.xlsx",//限制文件类型
            'auto'			:true,//是否自动上传
            'multi'			:false,//是否允许多文件上传
            'buttonText'	:"导入文档",
            'method'		:"POST",
            'formData':{"f_ssc_contentid" : <%=f_ssc_contentid%>},
            'onUploadComplete' : function(file,data) {//上传完成时触发 每个文件触发
            	console.log('onUploadComplete')
                var jsonData = JSON.parse(data);
                if(data != null && data != undefined && data != ''){
					jQuery.messager.alert('批量导入',jsonData);
				}
            },
            "onUploadStart":function(file){
				jQuery.messager.alert('批量导入','批量导入开始, 操作结果请稍后.');
				
            },
			'onUploadError' : function(file, errorCode, errorMsg, errorString) {
				if(errorMsg == '302'){
					jQuery.messager.alert('批量导入','批量导入失败，请检查登录状态或者无此权限!');
				}
			},
            onCancel : function(file) {
                alert(file.name + " 已取消上传~!");
            },
            onFallback : function() {
                alert("该浏览器无法使用!");
            }
        });
	}
</script>
</html>